package com.softer.wxzj.common.logic;

import com.softer.wxzj.common.enums.NumStrEnum;
import com.softer.wxzj.entity.BaseHouseInfo;
import com.softer.wxzj.entity.BaseOwnerInfo;
import com.softer.wxzj.entity.BaseOwnerInfoMap;
import com.softer.wxzj.mapper.BaseHouseInfoMapper;
import com.softer.wxzj.mapper.BaseOwnerInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.Period;

/**
 *    
 *  @ClassName: CalculateAmount
 *  @Description: 计算金额逻辑类
 *  @Author:  zcz
 *  @CreateDate: 2019-05-10   
 */
@Component
public class DepReqLogic {
    @Autowired
    private BaseHouseInfoMapper baseHouseInfoMapper;
    @Autowired
    private BaseOwnerInfoMapper baseOwnerInfoMapper;

    /**
     * 获取房屋是否已缴存或者缴存中   1是  0否
     *
     * @param id 房间id
     * @return
     */
    public String getIsDueState(String id) {
        BaseOwnerInfo baseOwnerInfo = baseOwnerInfoMapper.getInfoByAccNo(id);
        //0未缴存 1已缴存
        String isDueState = NumStrEnum.ZERO.getNum();
        String dueState = baseHouseInfoMapper.getDueStateById(id);
        //dueState = 4 未交，其余已缴存
        if (null != baseOwnerInfo) {
            if (NumStrEnum.FOUR.getNum().equals(dueState)) {
                //查询是否有在处理中的缴存进程
                int count = baseHouseInfoMapper.getCountDepReqListByHouseId(id, baseOwnerInfo.getId());
                if (count > 0) {
                    isDueState = NumStrEnum.ONE.getNum();
                }
            } else {
                BaseHouseInfo baseHouseInfo = baseHouseInfoMapper.getInfo(id);
                if (baseHouseInfo.getState().equals(NumStrEnum.ZERO.getNum())) {
                    isDueState = NumStrEnum.ZERO.getNum();
                } else {
                    isDueState = NumStrEnum.ONE.getNum();
                }
            }
        }
        return isDueState;
    }
}
